<template>
  <el-container>
    <!-- 头部内容 -->
    <el-header>
      <div>
        <img src="../assets/logo.png">
        <span>超市后台管理系统</span>
      </div>
      <el-button type="primary">退出</el-button>
    </el-header>
    <el-container>
      <!-- 左侧菜单 -->
      <el-aside :width="isCollapse ? '65px' : '250px'">
        <div class="expo" @click="isCollapse=!isCollapse">| | |</div>
        <el-menu
          :uniqueOpened="true"
          :collapse='isCollapse'
          :collapse-transition='false'
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#33333f"
          text-color="#fff"
          active-text-color="#409EFF">
          <el-submenu :index="item.id+''" v-for="(item,index) in list" :key="item.id">
            <template #title>
              <i :class="iconList[index]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <span @click="toPath(subItem.path)">{{ subItem.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
    export default {
      name:"home",
      data(){
        return{
          isCollapse:false,
          list:[],
          iconList:['el-icon-user-solid','el-icon-s-tools','el-icon-s-goods','el-icon-s-order','el-icon-s-data']
        }
      },
      created(){
        this.getMenuList();
      },
      methods: {
        //获取所有的左侧菜单
        getMenuList(){
          this.axios.get('menus').then(data=>{
            //console.log(data);
            this.list = data.data.data
          }).catch(err=>{
            console.log(err);
          })
        },
        handleOpen(key, keyPath) {
          console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
          console.log(key, keyPath);
        },
        //跳转路由
        toPath(path){
        //编程式跳转路由
          this.$router.push(path);
        }
      }
    }
  </script>

<style scoped>
.el-container{
  height: 100%;
}
.el-header{
  display: flex;
  color: #F8F8FF;
  background-color: #0f0f0f;
  /*弹性盒模型 左右两边对齐*/
  justify-content: space-between;
  padding-left: 10px;
/*内容居中对齐*/
  align-content: center;
  font-size: 24px;
}
.el-header div{
  display: flex;
  align-items: center;
}
.el-header div img{
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
.el-header div span {
  margin-left: 20px;
}
/*收缩条*/
.expo{
  background: #07292f;
  font-size: 14px;
  color: #fff;
  line-height: 28px;
  text-align: center;
  user-select: none;
  cursor: pointer;
}
.el-aside{
  background: #33333f;
  height: 100%;
}
.el-main{
  background-color: #fff;
}
</style>
